#!/usr/bin/env bash
version=$(lsb_release -r --short)
if [ "X${version}" = "X18.04" ]; then
  ROS_DISTRO=melodic
else
  ROS_DISTRO=kinetic
fi

#motion plan https://github.com/HKUST-Aerial-Robotics/Fast-Planner
#sudo apt-get install libnlopt-dev libarmadillo-dev -y
#sudo apt-get install ros-$ROS_DISTRO-moveit -y
mkdir -p ~/ct
cd ~/ct
if [ ! -d "nlopt-2.6.2" ]; then
  rm v2.6.2.tar.gz
  wget https://github.com/stevengj/nlopt/archive/v2.6.2.tar.gz
  tar -zxvf v2.6.2.tar.gz
  cd nlopt-2.6.2
  mkdir build
  cd build
  cmake ..
  make -j$(nproc)
  sudo make install
fi
cd ~

sudo apt install ros-$ROS_DISTRO-control-toolbox ros-$ROS_DISTRO-octomap-msgs ros-$ROS_DISTRO-octomap ros-$ROS_DISTRO-octomap-rviz-plugins ros-$ROS_DISTRO-octovis -y
sudo apt-get install ros-$ROS_DISTRO-desktop-full -y
#sudo apt-get install ros-$ROS_DISTRO-desktop
#sudo apt-get install ros-$ROS_DISTRO-ros-base

sudo apt install libfcl-dev wmctrl ros-$ROS_DISTRO-libsensors-monitor ros-$ROS_DISTRO-opencv-apps -y
# sudo apt install libfcl -y
sudo apt install libopenni2-dev vim zsh terminator libusb-1.0-0-dev -y
#sudo apt install ros-$ROS_DISTRO-opencv-candidate -y
sudo apt install ros-$ROS_DISTRO-mavros ros-$ROS_DISTRO-mavros-extras ros-$ROS_DISTRO-plotjuggler -y
sudo apt install ros-$ROS_DISTRO-octomap-ros -y
sudo apt install ompl-demos -y
sudo apt install python-gtk2-dev -y

sudo pip install --upgrade pip -i https://pypi.douban.com/simple
sudo -H pip install catkin_tools itchat gitpython testresources -i https://pypi.douban.com/simple
sudo -H pip install configparser -i https://pypi.douban.com/simple
sudo -H pip install simplekml -i https://pypi.douban.com/simple
sudo -H pip install azure-storage-blob -i https://pypi.tuna.tsinghua.edu.cn/simple

#sudo -H pip install tensorflow==1.5.0
#for ubuntu 18
#sudo -H pip install tensorflow-cpu -i https://pypi.tuna.tsinghua.edu.cn/simple
#sudo -H pip install tensorflow-cpu -i https://mirrors.ustc.edu.cn/pypi/web/simple
sudo -H pip install tensorflow-cpu -i https://pypi.douban.com/simple

#cd /opt/ros/$ROS_DISTRO/lib/
#sudo ln -s /opt/ros/$ROS_DISTRO/lib/liborocos-kdl.so.1.3 /opt/ros/$ROS_DISTRO/lib/liborocos-kdl.so.1.3.0

#前面环境已安装
#source ../install_opencv.sh
#source ../install_ouster_driver.sh
#source ../install_velodyne_sim.sh
#编译并安装DJI_OnboardSDK
#source ./install_dji_sdk_core.sh

#for PX4 Firmware
pip3 install --user jinja2 empy toml packaging numpy

#get tty permission
sudo systemctl stop nvgetty.service
sudo systemctl disable nvgetty.service
